home *** CD-ROM | disk | FTP | other *** search
- /* expense1.c: A structured version of the trip expense program */
-
- #include <stdio.h>
- #include <string.h>
-
- struct ExpenseRec { /* The trip expense record */
- char TripName[80], Date[80];
- int Mileage, Cost, Fringe;
- };
-
- void CheckWithBoss(struct ExpenseRec ExRec)
- /* The boss is very tough. He won't approve every trip. */
- {
- if (!stricmp(ExRec.TripName, "Hawaii") ||
- !stricmp(ExRec.TripName, "Tahiti"))
- printf("%s: You are fired for trying to sneak this one by\n",
- ExRec.TripName);
- else if (ExRec.Cost/4 < ExRec.Fringe)
- printf("The fringe expenses for the %s trip are too high\n",
- ExRec.TripName);
- else printf("The %s trip is ok\n", ExRec.TripName);
- }
-
- int I, ExCount;
- struct ExpenseRec ExRec[20]; /* A list of employee records */
-
- main()
- {
- printf("How many trips did you take? ");
- scanf("%d", &ExCount);
- for (I=0; I<ExCount; I++) {
- printf("Please enter the name of your trip: ");
- scanf("%s", ExRec[I].TripName);
- printf("Which date did you leave (mo/day/year)? ");
- scanf("%s", ExRec[I].Date);
- printf("Enter the number of miles for your trip: ");
- scanf("%d", &ExRec[I].Mileage);
- printf("Enter the cost of your trip: ");
- scanf("%d", &ExRec[I].Cost);
- printf("Enter the cost of your meals and entertainment: ");
- scanf("%d", &ExRec[I].Fringe);
- }
- for (I=0; I<ExCount; I++) CheckWithBoss(ExRec[I]);
- return 0;
- }
-
-